Skip to content

feat(clerk-js,clerk-react,nextjs,types): Drop experimental tag from GoogleOneTap - #3392

Merged
panteliselef merged 4 commits into
mainfrom
elef/prepare-one-tap-for-ga
May 20, 2024
Merged

feat(clerk-js,clerk-react,nextjs,types): Drop experimental tag from GoogleOneTap#3392
panteliselef merged 4 commits into
mainfrom
elef/prepare-one-tap-for-ga

Conversation

@panteliselef

@panteliselef panteliselef commented May 16, 2024

Copy link
Copy Markdown
Contributor

Description

Add support for GoogleOneTap. New APIs listed:

React component

  • <GoogleOneTap/>

Customize the UX of the prompt

<GoogleOneTap
  cancelOnTapOutside={false}
  itpSupport={false}
  fedCmSupport={false}
/>

Use the component from with Vanilla JS

  • Clerk.openGoogleOneTap(props: GoogleOneTapProps)
  • Clerk.closeGoogleOneTap()

Low level APIs for custom flows

  • await Clerk.authenticateWithGoogleOneTap({ token: 'xxxx'})
  • await Clerk.handleGoogleOneTapCallback()

We recommend using this two methods together in order and let Clerk to perform the correct redirections.

google.accounts.id.initialize({
  callback: async response => {
    const signInOrUp = await Clerk.authenticateWithGoogleOneTap({ token: response.credential})
    await Clerk.handleGoogleOneTapCallback(signInOrUp, {
      signInForceRedirectUrl: window.location.href,
    })
  },
});

In case you want to handle the redirection and session management yourself you can do so like this

google.accounts.id.initialize({
  callback: async response => {
    const signInOrUp = await Clerk.authenticateWithGoogleOneTap({ token: response.credential})
    if(signInOrUp.status === 'complete') {
        await Clerk.setActive({
          session: signInOrUp.createdSessionId
        })
    }
  },
});

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@panteliselef panteliselef self-assigned this May 16, 2024
@changeset-bot

changeset-bot Bot commented May 16, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e97824f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@clerk/clerk-js Minor
@clerk/nextjs Minor
@clerk/clerk-react Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/elements Patch
@clerk/remix Patch
@clerk/backend Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/clerk-sdk-node Patch
@clerk/testing Patch
@clerk/themes Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines -228 to -248
public __experimental_authenticateWithGoogleOneTap = async (
params: __experimental_AuthenticateWithGoogleOneTapParams,
): Promise<SignInResource | SignUpResource> => {
return this.create({
// TODO-ONETAP: Add new types when feature is ready for public beta
// @ts-expect-error
strategy: 'google_one_tap',
googleOneTapToken: params.token,
}).catch(err => {
if (isClerkAPIResponseError(err) && err.errors[0].code === 'external_account_not_found') {
return SignIn.clerk.client?.signUp.create({
// TODO-ONETAP: Add new types when feature is ready for public beta
// @ts-expect-error
strategy: 'google_one_tap',
googleOneTapToken: params.token,
});
}
throw err;
}) as Promise<SignInResource | SignUpResource>;
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved to Clerk.ts

Comment on lines +988 to +993
authenticateWithGoogleOneTap = async (
params: AuthenticateWithGoogleOneTapParams,
): Promise<SignInResource | SignUpResource> => {
const clerkjs = await this.#waitForClerkJS();
return clerkjs.authenticateWithGoogleOneTap(params);
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to highlight this change. This goes against the pattern we already have. But I cannot think of a reason why we cannot do this.

@panteliselef
panteliselef enabled auto-merge (squash) May 20, 2024 17:28
@panteliselef
panteliselef merged commit d6a9b3f into main May 20, 2024
@panteliselef
panteliselef deleted the elef/prepare-one-tap-for-ga branch May 20, 2024 17:39
panteliselef added a commit that referenced this pull request May 21, 2024
…oogleOneTap (#3392)

* feat(clerk-js,clerk-react,nextjs,types): Drop experimental tag from GoogleOneTap

* feat(clerk-js,clerk-react,nextjs,types): Add changeset

* test(chrome-extension): Update snapshots

(cherry picked from commit d6a9b3f)
@panteliselef panteliselef mentioned this pull request May 21, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants